package com.bookstore.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bookstore.entity.po.BookClassOP;
import com.bookstore.entity.po.OrderPO;
import com.bookstore.entity.pojo.R;
import com.bookstore.entity.vo.NameValueVO;
import com.bookstore.entity.vo.TodayVolumVO;
import com.bookstore.service.BookClassService;
import com.bookstore.service.BookService;
import com.bookstore.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("chart")
@CrossOrigin
public class ChartController {
    @Autowired
    BookClassService bookClassService;
    @Autowired
    BookService service;
    @Autowired
    OrderService orderService;

    @GetMapping("todayVolume")
    public R todayVolume () {

        List<TodayVolumVO> todayVolume = orderService.getTodayVolume();
        List<String > className = new ArrayList<>(todayVolume.size());
        List<Integer > num = new ArrayList<>(todayVolume.size());
        todayVolume.forEach(v -> {
            className.add(v.getClassName());
            num.add(v.getSum());
        });
        Map<String,Object> resMap = new HashMap<>();
        resMap.put("className",className);
        resMap.put("num",num);
        return R.success(resMap);
    }

    @GetMapping("classRatio")
    public R classRatio() {
        List<NameValueVO> nameValueVO =  orderService.getClassVolume();
        return R.success(nameValueVO);
    }
    @GetMapping("nearTM")
    public R nearTM() {
       List<NameValueVO> list = orderService.nearTM();
        List<String > names = new ArrayList<>(list.size());
        List<Float > values = new ArrayList<>(list.size());
        list.forEach(v -> {
            names.add(v.getName());
            values.add(v.getValue());
        });
        Map<String,Object> resMap = new HashMap<>();
        resMap.put("names",names);
        resMap.put("values",values);
       return R.success(resMap);
    }
}
